/**
 * Copyright 2017 by FREEMYPAL. Tianhua Information Technology Park (South) Building 4, 4th Floor, 
 * Longtian Road 195,Shanghai, P.R. China，200235. All rights reserved.
 *
 * This software is the confidential and proprietary information of FREEMYPAL
 * ("Confidential Information"). You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with FREEMYPAL.
 */
package com.roc.web.action.agent;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;

/**
 * @Description: 代理商统计信息查询
 * @author Jian Jang
 * @version 1.0 2017年7月28日
 */
public class AgencyMerSummarySearchCondition extends BaseSearchCondition {
	private static final long serialVersionUID = -3550378891206945730L;

	private String roleType;// 角色类型

	private String agentId;// 代理商id

	private String accountNo;// 代理商账户号

	private String agentName;// 代理商名称

	private String minDate; // 创建开始时间(年月日)
	private String maxDate; // 创建结束时间(年月日)

	public String getAgentId() {
		return agentId;
	}

	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}

	public String getMinDate() {
		return minDate;
	}

	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	public String getMaxDate() {
		return maxDate;
	}

	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}

	public String getRoleType() {
		return roleType;
	}

	public void setRoleType(String roleType) {
		this.roleType = roleType;
	}

	public String getAccountNo() {
		return accountNo;
	}

	public void setAccountNo(String accountNo) {
		this.accountNo = accountNo;
	}

	public String getAgentName() {
		return agentName;
	}

	public void setAgentName(String agentName) {
		this.agentName = agentName;
	}

	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		if (StringUtils.isNotBlank(agentId)) {
			filedBeanList.add(new WhereHQLFieldBean("ag.AGENT_ID", agentId, "=", false));
		}
		if (StringUtils.isNotBlank(accountNo)) {
			filedBeanList.add(new WhereHQLFieldBean("op.ACCOUNT_NO", accountNo, "=", false));
		}
		if (StringUtils.isNotBlank(agentName)) {
			filedBeanList.add(new WhereHQLFieldBean("ag.AGENT_NAME", "%" + agentName + "%", "like",
					false));
		}
		if (StringUtils.isNotBlank(minDate) && StringUtils.isNotBlank(minDate)) {
			filedBeanList.add(new WhereHQLFieldBean("ag.SUMMARY_DATE", minDate, ">=", false));
			filedBeanList.add(new WhereHQLFieldBean("ag.SUMMARY_DATE", maxDate, "<=", false));
		}
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		StringBuffer sb = new StringBuffer();
		sb.append("select count(*) from T_OPERATORS_MCHT_STATISTICS ag inner join T_OPERATORS op ")
				.append("on ag.agent_id= to_char(op.id) and op.role_type in ( '02', '03')  ")
				.append("where 1=1 ");
		return sb.toString();
	}

	@Override
	protected String getSearchHQL() {
		StringBuffer sb = new StringBuffer();

		sb.append(
				"select ag.*,op.account_no from T_OPERATORS_MCHT_STATISTICS ag inner join T_OPERATORS op ")
				.append("on ag.agent_id= to_char(op.id) and op.role_type in ( '02', '03')  ")
				.append("where 1=1 ");

		return sb.toString();
	}

	@Override
	protected String getOrderPartOfHQL() {
		return null;
	}

}
